<template>
    <div>
        <!-- <div class="indexPeople">
            <div class="userImage">
                <i class="iconfont icon-r-user2" style="font-size: 132px"></i>
            </div>

       
        </div> -->

        <br><br>
        <el-card>
            <el-table :data="queueInfo.queueData" stripe border>
                <el-table-column label="序号" type="index" width="50">
                </el-table-column>
                <el-table-column label="挂号单号" prop="oId"></el-table-column>
                <el-table-column label="患者id" prop="pId"></el-table-column>
                <el-table-column label="患者姓名" prop="pName"></el-table-column>


                <el-table-column label="操作" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="warning" style="font-size: 18px" v-if="scope.$index === 0"
                            @click="dealClick(scope.row.oId, scope.row.pId)">
                            <i class="iconfont icon-r-love" style="font-size: 26px"></i>
                            叫号处理
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>
<script>
import request from "@/utils/request.js";
import jwtDecode from "jwt-decode";
import { getToken } from "@/utils/storage.js";
import { toLoad } from "@/utils/initialize.js";
export default {
    name: "DoctorLayout",
    data() {
        return {
            userId: 1,
            orderPeople: 1,

            today: "",

            orderData: [],
            queueInfo: {
                dName: '',
                dSection: '',
                queueData: []
            }
        };
    },
    methods: {
        //token解码
        tokenDecode(token) {
            if (token !== null) return jwtDecode(token);
        },
        requestPeople() {
            request
                .get("order/orderPeopleByDid", {
                    params: {
                        dId: this.userId,
                    },
                })
                .then((res) => {
                    if (res.data.status !== 200)
                        return this.$message.error("数据请求失败");
                    this.orderPeople = res.data.data;
                });
        },
        //挂号处理//页面跳转传值
        dealClick(oId, pId) {
            this.$router.push({
                path: "/dealOrder",
                query: {
                    oId: oId,
                    pId: pId,
                },
            });
        },
        //获取挂号信息
        seeQueue(dId) {
            this.queueVisible = true;
            //查询队列信息
            const self = this;
            request
                .get("order/queue", {
                    params: {
                        dId: dId,
                    },
                })
                .then((res) => {
                    toLoad();
                    console.log("Response from backend:", res);
                    if (res.data.status != 200) {
                        self.$message.error("查询挂号队列信息失败");
                        return;
                    }
                    self.queueInfo = res.data.data
                });
        },
        requestOrder() {
            console.log(this.today)
            request
                .get("order/queue", {
                    params: {
                        dId: this.userId,
                        oStart: this.today,
                    },
                })
                .then((res) => {
                    toLoad();
                    if (res.data.status != 200)
                        return this.$message.error("获取数据失败");
                    this.orderData = res.data.data;
                });
        },
        //token解码
        tokenDecode(token) {
            if (token !== null) return jwtDecode(token);
        },
        //获取当天日期
        nowDay() {
            const nowDate = new Date();
            let date = {
                year: nowDate.getFullYear(),
                month: nowDate.getMonth() + 1,
                date: nowDate.getDate(),
            };
            if (date.date < 10) {
                date.date = "0" + date.date;
            }
            if (date.month < 10) {
                date.month = "0" + date.month;
            }
            this.today = date.year + "-" + date.month + "-" + date.date;
        },
    },
    created() {
        this.userId = this.tokenDecode(getToken()).dId;
        this.requestPeople();
        this.userId = this.tokenDecode(getToken()).dId;
        this.userName = this.tokenDecode(getToken()).dName;
        console.log(this.userId);
        console.log(this.userName);
        //获取当天日期
        this.nowDay();
        //获取订单信息
        this.seeQueue(this.userId);
    },
    mounted() {
        toLoad()
    }
};
</script>
<style lang="scss" scoped>
.userFont {
    height: 150px;
    width: 800px;
    color: white;
    float: right;

    .spanCure {
        font-size: 30px;
        margin-top: 60px;
        margin-bottom: 15px;
    }

    .spanPeople {
        font-size: 25px;
    }
}

.userImage {
    height: 150px;
    width: 150px;
    font-size: 130px;
    color: white;
    position: relative;
    left: 340px;
    top: 10px;
    float: left;
}

.indexPeople {
    height: 200px;
    width: 1440px;
    background: #58b9ae;
    margin-top: 50px;
    margin-left: 30px;
}
</style>